﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using System.Data;
using System.Data.OleDb;
namespace DAO
{
    public class HoaDonDAO
    {
        DataProvider dp;
        public HoaDonDAO()
        {
            dp = new DataProvider();
        }
        public bool ThemHoaDon(HoaDonDTO hddto)
        {
            bool flag = true;
            string sql = "insert into HoaDon(makhachhang,ngaylaphoadon,tongtien,tinhtrang) values (" + hddto.Makhachhang + " , '" + hddto.Ngaylaphoadon.ToShortDateString() + "','" + hddto.Tongtien + "',0)";
            if (!dp.ThucHienCauTruyVan(sql)) flag = false;
            return flag;
        }
        public int LayMaPhieuTuDong()
        {
            int maphieu = 0;
            string sql = "select * from HoaDon";
            DataTable table = new DataTable();
            table = dp.LayBangDuLieu(sql);
            DataRow dr = table.Rows[table.Rows.Count - 1];
            maphieu = int.Parse(dr[0].ToString());
            return maphieu;
        }
        public DataTable LayDSHoaDon()
        {
            DataTable table = new DataTable();
            string sql = "select * from HoaDon where tinhtrang = 0";
            table = dp.LayBangDuLieu(sql);
            return table;
        }
        public DataTable LayHDTheoKhachHang(int makh)
        {
            DataTable table = new DataTable();
            string sql = "select * from HoaDon where tinhtrang = 0 and makhachhang = " + makh + "";
            table = dp.LayBangDuLieu(sql);
            return table;
        }
    }
}
